package com.lancoo.answer.view.adapter.wordSpell;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.lancoo.answer.R;
import com.lancoo.answer.model.entity.wordSpell.WordKeyDetailBean;
import com.lancoo.answer.util.encodeUtils.TextUtils;

import java.util.List;

/**
 * Created by pengmi on 2022/1/19 14:59
 * Description:
 */
public class WordSpellAnswerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<WordKeyDetailBean> list;


    public WordSpellAnswerAdapter(List<WordKeyDetailBean> list) {
        this.list = list;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.ev_item_word_spell_write_answer, parent, false);
        return new VH(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        VH vh= (VH) holder;
        vh.initData(list.get(position),position==list.size()-1);
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public static class VH extends RecyclerView.ViewHolder{


        public VH(@NonNull View itemView) {
            super(itemView);
        }

        private void initData(WordKeyDetailBean bean,boolean isLast){
            TextView tv_answer = itemView.findViewById(R.id.tv_answer);
            tv_answer.setText(bean.getKeyStr());
            itemView.findViewById(R.id.view_item_space).setVisibility(!TextUtils.isEmpty(bean.getKeyStr())?View.GONE:View.VISIBLE);
            itemView.findViewById(R.id.line).setVisibility(!TextUtils.isEmpty(bean.getKeyStr())?View.GONE:View.VISIBLE);
            itemView.findViewById(R.id.view_space).setVisibility(!isLast&&bean.isNextSpace()?View.VISIBLE:View.GONE);
        }
    }


}
